package cn.mp.generator;

public class Test {

    private final static Object lock = new Object();

    public static void main(String[] args) {
        Ta ta = new Ta();
        Tb tb = new Tb();
        ta.start();
        tb.start();
    }

    static class Ta extends Thread {
        @Override
        public void run() {
            synchronized (lock) {
                try {
                    System.out.println("a1");
                    lock.wait();
                    System.out.println("a3");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    static class Tb extends Thread {
        @Override
        public void run() {

            synchronized (lock) {
                System.out.println("b1");
                lock.notify();
            }
                try {
                    Thread.sleep(2000L);
                    System.out.println("b2");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

        }
    }
}
